#!/bin/bash

WORK_DIR=$1
NAME_DPKG=$2
VERSION=$3
DEPENDENS=$4

cd $WORK_DIR

find -type f -print0|xargs -0 md5sum > ./DEBIAN/md5sums

find ./usr/ -mindepth 2 -type d -printf '/usr/%P\n'  >> ./DEBIAN/dirs
find ./etc/ -mindepth 2 -type d -printf '/etc/%P\n'  >> ./DEBIAN/dirs

{
echo "Package:$NAME_DPKG
Version: $VERSION
Provides: $NAME_DPKG
Depends:$DEPENDENS
Maintainer: Aleksev Semen
Architecture: amd64
Priority: optional
Section: other
Description: Install the program $NAME_DPKG"
} > ./DEBIAN/control

cd ..

dpkg-deb --build $WORK_DIR $NAME_DPKG-$VERSION.deb
